home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / libraries / display_tbl.lib.php < prev    next >
Encoding:
PHP Script  |  2004-12-09  |  97.1 KB  |  1,896 lines

  1. <?php
  2. /* $Id: display_tbl.lib.php,v 2.71 2004/12/09 18:27:10 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Set of functions used to display the records returned by a sql query
  7.  */
  8.  
  9. /**
  10.  * Defines the display mode to use for the results of a sql query
  11.  *
  12.  * It uses a synthetic string that contains all the required informations.
  13.  * In this string:
  14.  *   - the first two characters stand for the action to do while
  15.  *     clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
  16.  *     edit link...);
  17.  *   - the next two characters stand for the action to do while
  18.  *     clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
  19.  *     no delete link...);
  20.  *   - the next characters are boolean values (1/0) and respectively stand
  21.  *     for sorting links, navigation bar, "insert a new row" link, the
  22.  *     bookmark feature, the expand/collapse text/blob fields button and
  23.  *     the "display printable view" option.
  24.  *     Of course '0'/'1' means the feature won't/will be enabled.
  25.  *
  26.  * @param   string   the synthetic value for display_mode (see ยบ1 a few
  27.  *                   lines above for explanations)
  28.  * @param   integer  the total number of rows returned by the sql query
  29.  *                   without any programmatically appended "LIMIT" clause
  30.  *                   (just a copy of $unlim_num_rows if it exists, else
  31.  *                   computed inside this function)
  32.  *
  33.  * @return  array    an array with explicit indexes for all the display
  34.  *                   elements
  35.  *
  36.  * @global  string   the database name
  37.  * @global  string   the table name
  38.  * @global  integer  the total number of rows returned by the sql query
  39.  *                   without any programmatically appended "LIMIT" clause
  40.  * @global  array    the properties of the fields returned by the query
  41.  * @global  string   the url to return to in case of error in a sql
  42.  *                   statement
  43.  *
  44.  * @access  private
  45.  *
  46.  * @see     PMA_displayTable()
  47.  */
  48. function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
  49. {
  50.     global $db, $table;
  51.     global $unlim_num_rows, $fields_meta;
  52.     global $err_url;
  53.  
  54.     // 1. Initializes the $do_display array
  55.     $do_display              = array();
  56.     $do_display['edit_lnk']  = $the_disp_mode[0] . $the_disp_mode[1];
  57.     $do_display['del_lnk']   = $the_disp_mode[2] . $the_disp_mode[3];
  58.     $do_display['sort_lnk']  = (string) $the_disp_mode[4];
  59.     $do_display['nav_bar']   = (string) $the_disp_mode[5];
  60.     $do_display['ins_row']   = (string) $the_disp_mode[6];
  61.     $do_display['bkm_form']  = (string) $the_disp_mode[7];
  62.     $do_display['text_btn']  = (string) $the_disp_mode[8];
  63.     $do_display['pview_lnk'] = (string) $the_disp_mode[9];
  64.  
  65.     // 2. Display mode is not "false for all elements" -> updates the
  66.     // display mode
  67.     if ($the_disp_mode != 'nnnn000000') {
  68.         // 2.0 Print view -> set all elements to FALSE!
  69.         if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  70.             $do_display['edit_lnk']  = 'nn'; // no edit link
  71.             $do_display['del_lnk']   = 'nn'; // no delete link
  72.             $do_display['sort_lnk']  = (string) '0';
  73.             $do_display['nav_bar']   = (string) '0';
  74.             $do_display['ins_row']   = (string) '0';
  75.             $do_display['bkm_form']  = (string) '0';
  76.             $do_display['text_btn']  = (string) '0';
  77.             $do_display['pview_lnk'] = (string) '0';
  78.         }
  79.         // 2.1 Statement is a "SELECT COUNT", a
  80.         //     "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
  81.         //     contains a "PROC ANALYSE" part
  82.         else if ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
  83.             $do_display['edit_lnk']  = 'nn'; // no edit link
  84.             $do_display['del_lnk']   = 'nn'; // no delete link
  85.             $do_display['sort_lnk']  = (string) '0';
  86.             $do_display['nav_bar']   = (string) '0';
  87.             $do_display['ins_row']   = (string) '0';
  88.             $do_display['bkm_form']  = (string) '1';
  89.             if ($GLOBALS['is_analyse']) {
  90.                 $do_display['text_btn']  = (string) '1';
  91.             } else {
  92.                 $do_display['text_btn']  = (string) '0';
  93.             }
  94.             $do_display['pview_lnk'] = (string) '1';
  95.         }
  96.         // 2.2 Statement is a "SHOW..."
  97.         else if ($GLOBALS['is_show']) {
  98.             // 2.2.1 TODO : defines edit/delete links depending on show statement
  99.             $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
  100.             if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
  101.                 $do_display['edit_lnk'] = 'nn'; // no edit link
  102.                 $do_display['del_lnk']  = 'kp'; // "kill process" type edit link
  103.             }
  104.             else {
  105.                 // Default case -> no links
  106.                 $do_display['edit_lnk'] = 'nn'; // no edit link
  107.                 $do_display['del_lnk']  = 'nn'; // no delete link
  108.             }
  109.             // 2.2.2 Other settings
  110.             $do_display['sort_lnk']  = (string) '0';
  111.             $do_display['nav_bar']   = (string) '0';
  112.             $do_display['ins_row']   = (string) '0';
  113.             $do_display['bkm_form']  = (string) '1';
  114.             $do_display['text_btn']  = (string) '1';
  115.             $do_display['pview_lnk'] = (string) '1';
  116.         }
  117.         // 2.3 Other statements (ie "SELECT" ones) -> updates
  118.         //     $do_display['edit_lnk'], $do_display['del_lnk'] and
  119.         //     $do_display['text_btn'] (keeps other default values)
  120.         else {
  121.             $prev_table = $fields_meta[0]->table;
  122.             $do_display['text_btn']  = (string) '1';
  123.             for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
  124.                 $is_link = ($do_display['edit_lnk'] != 'nn'
  125.                             || $do_display['del_lnk'] != 'nn'
  126.                             || $do_display['sort_lnk'] != '0'
  127.                             || $do_display['ins_row'] != '0');
  128.                 // 2.3.2 Displays edit/delete/sort/insert links?
  129.                 if ($is_link
  130.                     && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
  131.                     $do_display['edit_lnk'] = 'nn'; // don't display links
  132.                     $do_display['del_lnk']  = 'nn';
  133.                     // TODO: May be problematic with same fields names in
  134.                     //       two joined table.
  135.                     // $do_display['sort_lnk'] = (string) '0';
  136.                     $do_display['ins_row']  = (string) '0';
  137.                     if ($do_display['text_btn'] == '1') {
  138.                         break;
  139.                     }
  140.                 } // end if (2.3.2)
  141.                 // 2.3.3 Always display print view link
  142.                 $do_display['pview_lnk']    = (string) '1';
  143.                 $prev_table = $fields_meta[$i]->table;
  144.             } // end for
  145.         } // end if..elseif...else (2.1 -> 2.3)
  146.     } // end if (2)
  147.  
  148.     // 3. Gets the total number of rows if it is unknown
  149.     if (isset($unlim_num_rows) && $unlim_num_rows != '') {
  150.         $the_total = $unlim_num_rows;
  151.     }
  152.     else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
  153.              && (!empty($db) && !empty($table))) {
  154.         $the_total   = PMA_countRecords($db, $table, TRUE);
  155.     }
  156.  
  157.     // 4. If navigation bar or sorting fields names urls should be
  158.     //    displayed but there is only one row, change these settings to
  159.     //    false
  160.     if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
  161.  
  162.         if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
  163.             // garvin: force display of navbar for vertical/horizontal display-choice.
  164.             // $do_display['nav_bar']  = (string) '0';
  165.             $do_display['sort_lnk'] = (string) '0';
  166.         }
  167.  
  168.     } // end if (3)
  169.  
  170.     // 5. Updates the synthetic var
  171.     $the_disp_mode = join('', $do_display);
  172.  
  173.     return $do_display;
  174. } // end of the 'PMA_setDisplayMode()' function
  175.  
  176.  
  177. /**
  178.  * Displays a navigation bar to browse among the results of a sql query
  179.  *
  180.  * @param   integer  the offset for the "next" page
  181.  * @param   integer  the offset for the "previous" page
  182.  * @param   string   the url-encoded query
  183.  *
  184.  * @global  string   the current language
  185.  * @global  string   the currect charset for MySQL
  186.  * @global  integer  the server to use (refers to the number in the
  187.  *                   configuration file)
  188.  * @global  string   the database name
  189.  * @global  string   the table name
  190.  * @global  string   the url to go back in case of errors
  191.  * @global  integer  the total number of rows returned by the sql query
  192.  * @global  integer  the total number of rows returned by the sql query
  193.  *                   without any programmatically appended "LIMIT" clause
  194.  * @global  integer  the current position in results
  195.  * @global  mixed    the maximum number of rows per page ('all' = no limit)
  196.  * @global  string   the display mode (horizontal/vertical/horizontalflipped)
  197.  * @global  integer  the number of row to display between two table headers
  198.  * @global  boolean  whether to limit the number of displayed characters of
  199.  *                   text type fields or not
  200.  *
  201.  * @access  private
  202.  *
  203.  * @see     PMA_displayTable()
  204.  */
  205. function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
  206. {
  207.     global $lang, $convcharset, $server, $db, $table;
  208.     global $goto;
  209.     global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
  210.     global $disp_direction, $repeat_cells;
  211.     global $dontlimitchars;
  212.     ?>
  213.  
  214. <!-- Navigation bar -->
  215. <table border="0" cellpadding="2" cellspacing="0">
  216. <tr>
  217.     <?php
  218.     // Move to the beginning or to the previous page
  219.     if ($pos > 0 && $session_max_rows != 'all') {
  220.         // loic1: patch #474210 from Gosha Sakovich - part 1
  221.         if ($GLOBALS['cfg']['NavigationBarIconic']) {
  222.             $caption1 = '<<';
  223.             $caption2 = ' < ';
  224.             $title1   = ' title="' . $GLOBALS['strPos1'] . '"';
  225.             $title2   = ' title="' . $GLOBALS['strPrevious'] . '"';
  226.         } else {
  227.             $caption1 = $GLOBALS['strPos1'] . ' <<';
  228.             $caption2 = $GLOBALS['strPrevious'] . ' <';
  229.             $title1   = '';
  230.             $title2   = '';
  231.         } // end if... else...
  232.         ?>
  233. <td>
  234.     <form action="sql.php" method="post">
  235.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  236.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  237.         <input type="hidden" name="pos" value="0" />
  238.         <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
  239.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  240.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  241.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  242.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  243.         <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
  244.     </form>
  245. </td>
  246. <td>
  247.     <form action="sql.php" method="post">
  248.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  249.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  250.         <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
  251.         <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
  252.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  253.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  254.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  255.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  256.         <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
  257.     </form>
  258. </td>
  259.         <?php
  260.     } // end move back
  261.     echo "\n";
  262.     ?>
  263. <td>
  264.        
  265. </td>
  266. <td align="center">
  267.     <form action="sql.php" method="post"
  268.         onsubmit="return (checkFormElementInRange(this, 'session_max_rows', 1) && checkFormElementInRange(this, 'pos', 0, <?php echo $unlim_num_rows - 1; ?>))">
  269.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  270.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  271.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  272.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  273.         <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
  274.         <input type="text" name="session_max_rows" size="3" value="<?php echo (($session_max_rows != 'all') ? $session_max_rows : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
  275.         <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
  276.         <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
  277.         <br />
  278.     <?php
  279.     // Display mode (horizontal/vertical and repeat headers)
  280.     $param1 = '            <select name="disp_direction">' . "\n"
  281.             . '                <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
  282.             . '                <option value="horizontalflipped"' . (($disp_direction == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
  283.             . '                <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
  284.             . '            </select>' . "\n"
  285.             . '           ';
  286.     $param2 = '            <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" class="textfield" />' . "\n"
  287.             . '           ';
  288.     echo '    ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
  289.     ?>
  290.     </form>
  291. </td>
  292. <td>
  293.        
  294. </td>
  295.     <?php
  296.     // Move to the next page or to the last one
  297.     if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
  298.         && $session_max_rows != 'all') {
  299.         // loic1: patch #474210 from Gosha Sakovich - part 2
  300.         if ($GLOBALS['cfg']['NavigationBarIconic']) {
  301.             $caption3 = ' > ';
  302.             $caption4 = '>>';
  303.             $title3   = ' title="' . $GLOBALS['strNext'] . '"';
  304.             $title4   = ' title="' . $GLOBALS['strEnd'] . '"';
  305.         } else {
  306.             $caption3 = '> ' . $GLOBALS['strNext'];
  307.             $caption4 = '>> ' . $GLOBALS['strEnd'];
  308.             $title3   = '';
  309.             $title4   = '';
  310.         } // end if... else...
  311.         echo "\n";
  312.         ?>
  313. <td>
  314.     <form action="sql.php" method="post">
  315.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  316.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  317.         <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
  318.         <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
  319.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  320.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  321.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  322.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  323.         <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
  324.     </form>
  325. </td>
  326. <td>
  327.     <form action="sql.php" method="post"
  328.         onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
  329.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  330.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  331.         <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $session_max_rows)- 1) * $session_max_rows); ?>" />
  332.         <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
  333.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  334.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  335.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  336.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  337.         <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> />
  338.     </form>
  339. </td>
  340.         <?php
  341.     } // end move toward
  342.  
  343.  
  344.     //page redirection
  345.     $pageNow = @floor($pos / $session_max_rows) + 1;
  346.     $nbTotalPage = @ceil($unlim_num_rows / $session_max_rows);
  347.  
  348.     if ($nbTotalPage > 1){ //if1
  349.        ?>
  350.    <td>
  351.           
  352.    </td>
  353.    <td>
  354.         <?php //<form> for keep the form alignment of button < and << ?>
  355.         <form>
  356.         <?php echo PMA_pageselector(
  357.                      'sql.php?sql_query='        . $encoded_query .
  358.                         '&session_max_rows=' . $session_max_rows .
  359.                         '&disp_direction='   . $disp_direction .
  360.                         '&repeat_cells='     . $repeat_cells .
  361.                         '&goto='             . $goto .
  362.                         '&dontlimitchars='   . $dontlimitchars .
  363.                         '&'                  . PMA_generate_common_url($db, $table) .
  364.                         '&',
  365.                      $session_max_rows,
  366.                      $pageNow,
  367.                      $nbTotalPage
  368.               );
  369.         ?>
  370.         </form>
  371.     </td>
  372.         <?php
  373.     } //_if1
  374.  
  375.  
  376.     // Show all the records if allowed
  377.     if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
  378.         echo "\n";
  379.         ?>
  380. <td>
  381.        
  382. </td>
  383. <td>
  384.     <form action="sql.php" method="post">
  385.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  386.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  387.         <input type="hidden" name="pos" value="0" />
  388.         <input type="hidden" name="session_max_rows" value="all" />
  389.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  390.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  391.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  392.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  393.         <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
  394.     </form>
  395. </td>
  396.         <?php
  397.     } // end show all
  398.     echo "\n";
  399.     ?>
  400. </tr>
  401. </table>
  402.  
  403.     <?php
  404. } // end of the 'PMA_displayTableNavigation()' function
  405.  
  406.  
  407. /**
  408.  * Displays the headers of the results table
  409.  *
  410.  * @param   array    which elements to display
  411.  * @param   array    the list of fields properties
  412.  * @param   integer  the total number of fields returned by the sql query
  413.  * @param   array    the analyzed query
  414.  *
  415.  * @return  boolean  always true
  416.  *
  417.  * @global  string   the current language
  418.  * @global  string   the current charset for MySQL
  419.  * @global  integer  the server to use (refers to the number in the
  420.  *                   configuration file)
  421.  * @global  string   the database name
  422.  * @global  string   the table name
  423.  * @global  string   the sql query
  424.  * @global  string   the url to go back in case of errors
  425.  * @global  integer  the total number of rows returned by the sql query
  426.  * @global  integer  the current position in results
  427.  * @global  integer  the maximum number of rows per page
  428.  * @global  array    informations used with vertical display mode
  429.  * @global  string   the display mode (horizontal/vertical/horizontalflipped)
  430.  * @global  integer  the number of row to display between two table headers
  431.  * @global  boolean  whether to limit the number of displayed characters of
  432.  *                   text type fields or not
  433.  *
  434.  * @access  private
  435.  *
  436.  * @see     PMA_displayTable()
  437.  */
  438. function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
  439. {
  440.     global $lang, $convcharset, $server, $db, $table;
  441.     global $goto, $text_url;
  442.     global $sql_query, $num_rows, $pos, $session_max_rows;
  443.     global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
  444.     global $dontlimitchars;
  445.  
  446.     if ($analyzed_sql == '') {
  447.         $analyzed_sql = array();
  448.     }
  449.  
  450.     // can the result be sorted?
  451.     if ($is_display['sort_lnk'] == '1') {
  452.  
  453.         // Just as fallback
  454.         $unsorted_sql_query     = $sql_query;
  455.         if (isset($analyzed_sql[0]['unsorted_query'])) {
  456.             $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
  457.         }
  458.  
  459.         // we need $sort_expression and $sort_expression_nodir
  460.         // even if there are many table references
  461.  
  462.         $sort_expression = trim(str_replace('  ', ' ',$analyzed_sql[0]['order_by_clause']));
  463.  
  464.         // Get rid of ASC|DESC (TODO: analyzer)
  465.         preg_match('@(.*)([[:space:]]*(ASC|DESC))@si',$sort_expression,$matches);
  466.         $sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
  467.  
  468.         // sorting by indexes, only if it makes sense (only one table ref)
  469.         if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  470.             isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
  471.             isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
  472.  
  473.             // grab indexes data:
  474.             PMA_DBI_select_db($db);
  475.             if (!defined('PMA_IDX_INCLUDED')) {
  476.                 $ret_keys = PMA_get_indexes($table);
  477.             }
  478.  
  479.             $prev_index = '';
  480.             foreach ($ret_keys as $row) {
  481.  
  482.                 if ($row['Key_name'] != $prev_index ){
  483.                     $indexes[]  = $row['Key_name'];
  484.                     $prev_index = $row['Key_name'];
  485.                 }
  486.                 $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
  487.                 $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
  488.                 if (isset($row['Cardinality'])) {
  489.                     $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
  490.                 }
  491.             //    I don't know what does the following column mean....
  492.             //    $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
  493.                 $indexes_info[$row['Key_name']]['Comment']         = (isset($row['Comment']))
  494.                                                                    ? $row['Comment']
  495.                                                                    : '';
  496.                 $indexes_info[$row['Key_name']]['Index_type']      = (isset($row['Index_type']))
  497.                                                                    ? $row['Index_type']
  498.                                                                    : '';
  499.  
  500.                 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
  501.                 if (isset($row['Sub_part'])) {
  502.                     $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
  503.                 }
  504.             } // end while
  505.  
  506.             // do we have any index?
  507.             if (isset($indexes_data)) {
  508.  
  509.                 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  510.                     $span = $fields_cnt;
  511.                     if ($is_display['edit_lnk'] != 'nn') $span++;
  512.                     if ($is_display['del_lnk'] != 'nn') $span++;
  513.                     if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') $span++;
  514.                 } else {
  515.                     $span = $num_rows + floor($num_rows/$repeat_cells) + 1;
  516.                 }
  517.  
  518.                 echo '<form action="sql.php" method="post">' . "\n";
  519.                 echo PMA_generate_common_hidden_inputs($db, $table, 5);
  520.                 echo '<input type="hidden" name="pos" value="' . $pos .  '" />' . "\n";
  521.                 echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
  522.                 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
  523.                 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
  524.                 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
  525.                 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query">' . "\n";
  526.                 $used_index = false;
  527.                 $local_order = (isset($sort_expression) ? $sort_expression : '');
  528.                 foreach ($indexes_data AS $key => $val) {
  529.                     $asc_sort = '';
  530.                     $desc_sort = '';
  531.                     foreach ($val AS $key2 => $val2) {
  532.                         $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
  533.                         $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
  534.                     }
  535.                     $asc_sort = substr($asc_sort, 0, -3);
  536.                     $desc_sort = substr($desc_sort, 0, -3);
  537.                     $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
  538.                     echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
  539.                     echo "\n";
  540.                     echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
  541.                     echo "\n";
  542.                 }
  543.                 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"' ) . '>' . $GLOBALS['strNone'] . '</option>';
  544.                 echo "\n";
  545.                 echo '</select> ';
  546.                 echo "\n";
  547.                 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
  548.                 echo "\n";
  549.                 echo '</form>';
  550.                 echo "\n";
  551.             }
  552.         }
  553.     }
  554.  
  555.  
  556.     $vertical_display['emptypre']   = 0;
  557.     $vertical_display['emptyafter'] = 0;
  558.     $vertical_display['textbtn']    = '';
  559.  
  560.  
  561.     // Start of form for multi-rows delete
  562.  
  563.     if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp' ) {
  564.         echo '<form method="post" action="tbl_row_delete.php" name="rowsDeleteForm">' . "\n";
  565.         echo PMA_generate_common_hidden_inputs($db, $table, 1);
  566.         echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
  567.         echo '<input type="hidden" name="repeat_cells"   value="' . $repeat_cells   . '" />' . "\n";
  568.         echo '<input type="hidden" name="goto"           value="sql.php" />' . "\n";
  569.         echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
  570.     }
  571.  
  572.     echo '<!-- Results table -->' . "\n"
  573.        . '<table id="table_results" ';
  574.     if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  575.         echo 'border="1" cellpadding="2" cellspacing="0"';
  576.     } else {
  577.         echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="2" cellspacing="1"';
  578.     }
  579.     echo '>' . "\n";
  580.     if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  581.         ?>
  582. <!-- Results table headers -->
  583. <tr>
  584.         <?php
  585.         echo "\n";
  586.     }
  587.  
  588.     // 1. Displays the full/partial text button (part 1)...
  589.     if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  590.         $colspan  = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
  591.                   ? ' colspan="3"'
  592.                   : '';
  593.     } else {
  594.         $rowspan  = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
  595.                   ? ' rowspan="3"'
  596.                   : '';
  597.     }
  598.     $text_url = 'sql.php?'
  599.               . PMA_generate_common_url($db, $table)
  600.               . '&sql_query=' . urlencode($sql_query)
  601.               . '&pos=' . $pos
  602.               . '&session_max_rows=' . $session_max_rows
  603.               . '&pos=' . $pos
  604.               . '&disp_direction=' . $disp_direction
  605.               . '&repeat_cells=' . $repeat_cells
  606.               . '&goto=' . $goto
  607.               . '&dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
  608.  
  609.     //     ... before the result table
  610.     if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
  611.         && $is_display['text_btn'] == '1') {
  612.         $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  613.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  614.             ?>
  615. <th class="td" colspan="<?php echo $fields_cnt; ?>" align="center">
  616.     <a href="<?php echo $text_url; ?>">
  617.         <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_'.(($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png'; ?>" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
  618. </th>
  619. </tr>
  620.  
  621. <tr>
  622.             <?php
  623.         } // end horizontal/horizontalflipped mode
  624.         else {
  625.             echo "\n";
  626.             ?>
  627. <tr>
  628. <th class="td" colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>" align="center">
  629.     <a href="<?php echo $text_url; ?>">
  630.         <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png'; ?>" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
  631. </th>
  632. </tr>
  633.             <?php
  634.         } // end vertical mode
  635.     }
  636.  
  637.     //     ... at the left column of the result table header if possible
  638.     //     and required
  639.     else if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
  640.         $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  641.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  642.             echo "\n";
  643.             ?>
  644. <th class="td" <?php echo $colspan; ?> align="center">
  645.     <a href="<?php echo $text_url; ?>">
  646.         <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png'; ?>" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
  647. </th>
  648.             <?php
  649.         } // end horizontal/horizontalflipped mode
  650.         else {
  651.             $vertical_display['textbtn'] = '    <th class="td" ' . $rowspan . ' align="center" valign="middle">' . "\n"
  652.                                          . '        <a href="' . $text_url . '">' . "\n"
  653.                                          . '            <img src="' . $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png" border="0" width="50" height="20" alt="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" /></a>' . "\n"
  654.                                          . '    </th>' . "\n";
  655.         } // end vertical mode
  656.     }
  657.  
  658.     //     ... else if no button, displays empty(ies) col(s) if required
  659.     else if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
  660.              && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
  661.         $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  662.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  663.             echo "\n";
  664.             ?>
  665. <td<?php echo $colspan; ?>></td>
  666.             <?php
  667.             echo "\n";
  668.         } // end horizontal/horizontalfipped mode
  669.         else {
  670.             $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
  671.         } // end vertical mode
  672.     }
  673.  
  674.     // 2. Displays the fields' name
  675.     // 2.0 If sorting links should be used, checks if the query is a "JOIN"
  676.     //     statement (see 2.1.3)
  677.  
  678.     // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']).
  679.     //       Do not show comments, if using horizontalflipped mode, because of space usage
  680.     if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
  681.         $comments_map = array();
  682.         foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
  683.  
  684.             $tb = $tbl['table_true_name'];
  685.  
  686.             $comments_map[$tb] = PMA_getComments($db, $tb);
  687.         }
  688.     }
  689.  
  690.     if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
  691.         require_once('./libraries/transformations.lib.php');
  692.         $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
  693.     }
  694.  
  695.     if ($is_display['sort_lnk'] == '1') {
  696.         //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt);
  697.         $is_join = (isset($analyzed_sql[0]['queryflags']['join']) ?TRUE:FALSE);
  698.         $select_expr = $analyzed_sql[0]['select_expr_clause'];
  699.     } else {
  700.         $is_join = FALSE;
  701.     }
  702.  
  703.     // garvin: See if we have to highlight any header fields of a WHERE query.
  704.     //  Uses SQL-Parser results.
  705.     $highlight_columns = array();
  706.     if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  707.         isset($analyzed_sql[0]['where_clause_identifiers'])) {
  708.  
  709.         $wi = 0;
  710.         if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
  711.             foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
  712.                 $highlight_columns[$wci] = 'true';
  713.             }
  714.         }
  715.     }
  716.  
  717.     for ($i = 0; $i < $fields_cnt; $i++) {
  718.         // garvin: See if this column should get highlight because it's used in the
  719.         //  where-query.
  720.         if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
  721.             $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
  722.         } else {
  723.             $column_style = '';
  724.         }
  725.  
  726.         // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
  727.         if (isset($comments_map) &&
  728.                 isset($comments_map[$fields_meta[$i]->table]) &&
  729.                 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
  730.             /*$comments_table_wrap_pre = '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><th>';
  731.             $comments_table_wrap_post = '</th></tr><tr><th style="font-size: 8pt; font-weight: normal">' . htmlspecialchars($comments_map[$fields_meta[$i]->name]) . '</td></tr></table>';*/
  732.             $comments_table_wrap_pre = '';
  733.             $comments_table_wrap_post = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
  734.         } else {
  735.             $comments_table_wrap_pre = '';
  736.             $comments_table_wrap_post = '';
  737.         }
  738.  
  739.         // 2.1 Results can be sorted
  740.         if ($is_display['sort_lnk'] == '1') {
  741.  
  742.             // 2.1.1 Checks if the table name is required; it's the case
  743.             //       for a query with a "JOIN" statement and if the column
  744.             //       isn't aliased, or in queries like
  745.             //       SELECT `1`.`master_field` , `2`.`master_field`
  746.             //       FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
  747.  
  748.             if (($is_join
  749.                 //&& !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name . '~i', $select_stt[1], $parts))
  750.                 && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name . '~i', $select_expr, $parts))
  751.                || ( isset($analyzed_sql[0]['select_expr'][$i]['expr'])
  752.                    && isset($analyzed_sql[0]['select_expr'][$i]['column'])
  753.                    && $analyzed_sql[0]['select_expr'][$i]['expr'] !=
  754.                    $analyzed_sql[0]['select_expr'][$i]['column']
  755.                   && !empty($fields_meta[$i]->table)) ) {
  756.                 //$sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
  757.                 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . ' . ';
  758.             } else {
  759.                 $sort_tbl = '';
  760.             }
  761.             // 2.1.2 Checks if the current column is used to sort the
  762.             //       results
  763.             if (empty($sort_expression)) {
  764.                 $is_in_sort = FALSE;
  765.             } else {
  766.                 // field name may be preceded by a space, or any number
  767.                 // of characters followed by a dot (tablename.fieldname)
  768.                 // so do a direct comparison
  769.                 // for the sort expression (avoids problems with queries
  770.                 // like "SELECT id, count(id)..." and clicking to sort
  771.                 // on id or on count(id) )
  772.                 $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? TRUE : FALSE);
  773.             }
  774.             // 2.1.3 Check the field name for backquotes.
  775.             //       If it contains some, it's probably a function column
  776.             //       like 'COUNT(`field`)'
  777.             if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
  778.                 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
  779.             } else {
  780.                 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
  781.             }
  782.             // 2.1.4 Do define the sorting url
  783.             if (!$is_in_sort) {
  784.                 // loic1: patch #455484 ("Smart" order)
  785.                 $cfg['Order']  = strtoupper($GLOBALS['cfg']['Order']);
  786.                 if ($cfg['Order'] == 'SMART') {
  787.                     $cfg['Order'] = (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
  788.                 }
  789.                 $sort_order .= $cfg['Order'];
  790.                 $order_img   = '';
  791.             }
  792.             else if (preg_match('@[[:space:]]ASC$@i', $sort_expression)) {
  793.                 $sort_order .= ' DESC';
  794.                 $order_img   = ' <img src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" border="0" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
  795.             }
  796.             else if (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
  797.                 $sort_order .= ' ASC';
  798.                 $order_img   = ' <img src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" border="0" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
  799.             }
  800.             if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
  801.                 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
  802.             } else {
  803.                 $sorted_sql_query = $unsorted_sql_query . $sort_order;
  804.             }
  805.             $url_query = PMA_generate_common_url($db, $table)
  806.                        . '&pos=' . $pos
  807.                        . '&session_max_rows=' . $session_max_rows
  808.                        . '&disp_direction=' . $disp_direction
  809.                        . '&repeat_cells=' . $repeat_cells
  810.                        . '&dontlimitchars=' . $dontlimitchars
  811.                        . '&sql_query=' . urlencode($sorted_sql_query);
  812.  
  813.             // 2.1.5 Displays the sorting url
  814.             // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
  815.             //                    enable sord order swapping for image
  816.             $order_onmouse = '';
  817.             if (isset($order_img) && $order_img!='') {
  818.                 if (strstr($order_img,'asc')) {
  819.                     $order_onmouse.= ' onmouseover="if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }"'
  820.                                    .' onmouseout="if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }"';
  821.                 } else if (strstr($order_img,'desc')) {
  822.                     $order_onmouse.= ' onmouseover="if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }"'
  823.                                    .' onmouseout="if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }"';
  824.                 }
  825.             }
  826.             $order_link_pre  = '<a href="sql.php?' . $url_query . '" ' . (($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') ? 'style="direction: ltr; writing-mode: tb-rl;"' : '') . ' title="' . $GLOBALS['strSort'] . '"' . $order_onmouse . '>';
  827.             $order_link_post = '</a>';
  828.             $order_link_content = ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
  829.             $order_link_words = explode(' ', $order_link_content);
  830.             if (isset($order_link_words[1])) {
  831.                 $order_last_word_index = count($order_link_words)-1;
  832.                 $order_last_word = $order_link_words[$order_last_word_index];
  833.                 unset($order_link_words[$order_last_word_index]);
  834.                 $order_link = $order_link_pre . implode(' ', $order_link_words)
  835.                             . ' <div class="nowrap">' . $order_last_word . $order_img . '</div>' . $order_link_post . "\n";
  836.             } else {
  837.                 $order_link = '<div class="nowrap">' . $order_link_pre . $order_link_content . $order_link_post . $order_img . '</div>' . "\n";
  838.             }
  839.  
  840.             if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  841.                 echo "\n";
  842.                 ?>
  843. <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
  844.     <?php echo $comments_table_wrap_pre; ?>
  845.     <?php echo $order_link; ?>
  846.     <?php echo $comments_table_wrap_post; ?>
  847. </th>
  848.                 <?php
  849.             }
  850.             $vertical_display['desc'][] = '    <th ' . $column_style . '>' . "\n"
  851.                                         . $comments_table_wrap_pre
  852.                                         . $order_link
  853.                                         . $comments_table_wrap_post
  854.                                         . '    </th>' . "\n";
  855.         } // end if (2.1)
  856.  
  857.         // 2.2 Results can't be sorted
  858.         else {
  859.             if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  860.                 echo "\n";
  861.                 ?>
  862. <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>  <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style="direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
  863.     <?php echo $comments_table_wrap_pre; ?>
  864.     <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
  865.     <?php echo $comments_table_wrap_post; ?>
  866. </th>
  867.                 <?php
  868.             }
  869.             $vertical_display['desc'][] = '    <th ' . $column_style . '>' . "\n"
  870.                                         . $comments_table_wrap_pre
  871.                                         . '        ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
  872.                                         . $comments_table_wrap_post
  873.                                         . '    </th>';
  874.         } // end else (2.2)
  875.     } // end for
  876.  
  877.     // 3. Displays the full/partial text button (part 2) at the right
  878.     //    column of the result table header if possible and required...
  879.     if ($GLOBALS['cfg']['ModifyDeleteAtRight']
  880.         && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
  881.         && $is_display['text_btn'] == '1') {
  882.         $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
  883.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  884.             echo "\n";
  885.             ?>
  886. <th class="td" <?php echo $colspan; ?> align="center">
  887.     <a href="<?php echo $text_url; ?>">
  888.         <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png'; ?>" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
  889. </th>
  890.             <?php
  891.         } // end horizontal/horizontalflipped mode
  892.         else {
  893.             $vertical_display['textbtn'] = '    <th class="td" ' . $rowspan . ' align="center" valign="middle">' . "\n"
  894.                                          . '        <a href="' . $text_url . '">' . "\n"
  895.                                          . '            <img src="' . $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png" border="0" width="50" height="20" alt="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" /></a>' . "\n"
  896.                                          . '    </th>' . "\n";
  897.         } // end vertical mode
  898.     }
  899.  
  900.     //     ... else if no button, displays empty cols if required
  901.     // (unless coming from Browse mode print view)
  902.     else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
  903.              && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
  904.              && (!$GLOBALS['is_header_sent'])) {
  905.         $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
  906.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  907.             echo "\n";
  908.             ?>
  909. <td<?php echo $colspan; ?>></td>
  910.             <?php
  911.         } // end horizontal/horizontalflipped mode
  912.         else {
  913.             $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
  914.         } // end vertical mode
  915.     }
  916.  
  917.     if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  918.         echo "\n";
  919.         ?>
  920. </tr>
  921.         <?php
  922.     }
  923.     echo "\n";
  924.  
  925.     return TRUE;
  926. } // end of the 'PMA_displayTableHeaders()' function
  927.  
  928.  
  929.  
  930. /**
  931.  * Displays the body of the results table
  932.  *
  933.  * @param   integer  the link id associated to the query which results have
  934.  *                   to be displayed
  935.  * @param   array    which elements to display
  936.  * @param   array    the list of relations
  937.  * @param   array    the analyzed query
  938.  *
  939.  * @return  boolean  always true
  940.  *
  941.  * @global  string   the current language
  942.  * @global  string   the current charset for MySQL
  943.  * @global  integer  the server to use (refers to the number in the
  944.  *                   configuration file)
  945.  * @global  string   the database name
  946.  * @global  string   the table name
  947.  * @global  string   the sql query
  948.  * @global  string   the url to go back in case of errors
  949.  * @global  integer  the current position in results
  950.  * @global  integer  the maximum number of rows per page
  951.  * @global  array    the list of fields properties
  952.  * @global  integer  the total number of fields returned by the sql query
  953.  * @global  array    informations used with vertical display mode
  954.  * @global  string   the display mode (horizontal/vertical/horizontalflipped)
  955.  * @global  integer  the number of row to display between two table headers
  956.  * @global  boolean  whether to limit the number of displayed characters of
  957.  *                   text type fields or not
  958.  *
  959.  * @access  private
  960.  *
  961.  * @see     PMA_displayTable()
  962.  */
  963. function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
  964. {
  965.     global $lang, $convcharset, $server, $db, $table;
  966.     global $goto;
  967.     global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
  968.     global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
  969.     global $dontlimitchars;
  970.     global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
  971.  
  972.     $url_sql_query          = $sql_query;
  973.  
  974.     // query without conditions to shorten urls when needed, 200 is just
  975.     // guess, it should depend on remaining url length
  976.  
  977.     if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  978.         isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
  979.         strlen($sql_query) > 200) {
  980.  
  981.         $url_sql_query = 'SELECT ';
  982.         if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
  983.             $url_sql_query .= ' DISTINCT ';
  984.         }
  985.         $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
  986.         if (!empty($analyzed_sql[0]['from_clause'])) {
  987.             $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
  988.         }
  989.     }
  990.  
  991.     if (!is_array($map)) {
  992.         $map = array();
  993.     }
  994.     ?>
  995. <!-- Results table body -->
  996.     <?php
  997.     echo "\n";
  998.  
  999.     $row_no                         = 0;
  1000.     $vertical_display['edit']       = array();
  1001.     $vertical_display['delete']     = array();
  1002.     $vertical_display['data']       = array();
  1003.     $vertical_display['row_delete'] = array();
  1004.  
  1005.     // Correction uva 19991216 in the while below
  1006.     // Previous code assumed that all tables have keys, specifically that
  1007.     // the phpMyAdmin GUI should support row delete/edit only for such
  1008.     // tables.
  1009.     // Although always using keys is arguably the prescribed way of
  1010.     // defining a relational table, it is not required. This will in
  1011.     // particular be violated by the novice.
  1012.     // We want to encourage phpMyAdmin usage by such novices. So the code
  1013.     // below has been changed to conditionally work as before when the
  1014.     // table being displayed has one or more keys; but to display
  1015.     // delete/edit options correctly for tables without keys.
  1016.  
  1017.     // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
  1018.     //        to get the NULL values
  1019.  
  1020.     // rabus: This function needs a little rework.
  1021.     //        Using MYSQL_BOTH just pollutes the memory!
  1022.  
  1023.     // ne0x:  Use function PMA_DBI_fetch_array() due to mysqli
  1024.     //        compatibility. Now this function is wrapped.
  1025.  
  1026.     while ($row = PMA_DBI_fetch_row($dt_result)) {
  1027.         // lem9: "vertical display" mode stuff
  1028.         if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
  1029.             echo '<tr>' . "\n";
  1030.  
  1031.             for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
  1032.                 echo '    <th class="td"> </th>' . "\n";
  1033.             }
  1034.  
  1035.             foreach ($vertical_display['desc'] AS $key => $val) {
  1036.                 echo $val;
  1037.             }
  1038.  
  1039.             for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
  1040.                 echo '    <th class="td"> </th>' . "\n";
  1041.             }
  1042.  
  1043.             echo '</tr>' . "\n";
  1044.         } // end if
  1045.  
  1046.         if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
  1047.             $bgcolor = '#ffffff';
  1048.         } else {
  1049.             $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
  1050.         }
  1051.  
  1052.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  1053.             // loic1: pointer code part
  1054.             $on_mouse     = '';
  1055.             if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
  1056.                 if ($GLOBALS['cfg']['BrowsePointerEnable'] == TRUE) {
  1057.                     $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
  1058.                               . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
  1059.                 } else {
  1060.                     $on_mouse = '';
  1061.                 }
  1062.                 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) {
  1063.                     $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
  1064.                 }
  1065.             } // end if
  1066.             ?>
  1067. <tr<?php echo $on_mouse; ?>>
  1068.             <?php
  1069.             echo "\n";
  1070.         }
  1071.  
  1072.         // 1. Prepares the row (gets primary keys to use)
  1073.         if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
  1074.             // 1.1 Results from a "SELECT" statement -> builds the
  1075.             //     "primary" key to use in links
  1076.             if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
  1077.                 $uva_condition     = urlencode(PMA_getUvaCondition($dt_result, $fields_cnt, $fields_meta, $row));
  1078.             } // end if (1.1)
  1079.  
  1080.             // 1.2 Defines the urls for the modify/delete link(s)
  1081.             $url_query  = PMA_generate_common_url($db, $table)
  1082.                         . '&pos=' . $pos
  1083.                         . '&session_max_rows=' . $session_max_rows
  1084.                         . '&disp_direction=' . $disp_direction
  1085.                         . '&repeat_cells=' . $repeat_cells
  1086.                         . '&dontlimitchars=' . $dontlimitchars;
  1087.  
  1088.             // We need to copy the value or else the == 'both' check will always return true
  1089.             $propicon = (string)$GLOBALS['cfg']['PropertiesIconic'];
  1090.  
  1091.             if ($propicon == 'both') {
  1092.                 $iconic_spacer = '<div class="nowrap">';
  1093.             } else {
  1094.                 $iconic_spacer = '';
  1095.             }
  1096.  
  1097.             // 1.2.1 Modify link(s)
  1098.             if ($is_display['edit_lnk'] == 'ur') { // update row case
  1099. //                    $lnk_goto = 'sql.php'
  1100. //                             . '?' . str_replace('&', '&', $url_query)
  1101. //                              . '&sql_query=' . urlencode($sql_query)
  1102. //                              . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
  1103. // to reduce the length of the URL, because of some browsers limitations:
  1104.                 $lnk_goto = 'sql.php';
  1105.  
  1106.                 $edit_url = 'tbl_change.php'
  1107.                           . '?' . $url_query
  1108.                           . '&primary_key=' . $uva_condition
  1109.                           . '&sql_query=' . urlencode($url_sql_query)
  1110.                           . '&goto=' . urlencode($lnk_goto);
  1111.                 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
  1112.                     $edit_str = $GLOBALS['strEdit'];
  1113.                 } else {
  1114.                     $edit_str = $iconic_spacer . '<img width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" border="0" />';
  1115.                     if ($propicon == 'both') {
  1116.                         $edit_str .= ' ' . $GLOBALS['strEdit'] . '</div>';
  1117.                     }
  1118.                 }
  1119.             } // end if (1.2.1)
  1120.  
  1121.             if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) {
  1122.                 $bookmark_go = '<a href="read_dump.php?'
  1123.                                 . PMA_generate_common_url($row[1], '')
  1124.                                 . '&id_bookmark=' . $row[0]
  1125.                                 . '&action_bookmark=0'
  1126.                                 . '&action_bookmark_all=1'
  1127.                                 . '&SQL=' . $GLOBALS['strExecuteBookmarked']
  1128.                                 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
  1129.  
  1130.                 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
  1131.                     $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
  1132.                 } else {
  1133.                     $bookmark_go .= $iconic_spacer . '<img width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" border="0" />';
  1134.                     if ($propicon == 'both') {
  1135.                         $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</div>';
  1136.                     }
  1137.                 }
  1138.  
  1139.                 $bookmark_go .= '</a>';
  1140.             } else {
  1141.                 $bookmark_go = '';
  1142.             }
  1143.  
  1144.             // 1.2.2 Delete/Kill link(s)
  1145.             if ($is_display['del_lnk'] == 'dr') { // delete row case
  1146.                 $lnk_goto = 'sql.php'
  1147.                           . '?' . str_replace('&', '&', $url_query)
  1148.                           . '&sql_query=' . urlencode($url_sql_query)
  1149.                           . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
  1150.                           . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
  1151.                 $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . '+LIMIT+1';
  1152.                 $del_url  = 'sql.php'
  1153.                           . '?' . $url_query
  1154.                           . '&sql_query=' . $del_query
  1155.                           . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
  1156.                           . '&goto=' . urlencode($lnk_goto);
  1157.                 $js_conf  = 'DELETE FROM ' . PMA_jsFormat($table)
  1158.                           . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
  1159.                           . ' LIMIT 1';
  1160.                 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
  1161.                     $del_str = $GLOBALS['strDelete'];
  1162.                 } else {
  1163.                     $del_str = $iconic_spacer . '<img width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" border="0" />';
  1164.                     if ($propicon == 'both') {
  1165.                         $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>';
  1166.                     }
  1167.                 }
  1168.             } else if ($is_display['del_lnk'] == 'kp') { // kill process case
  1169.                 $lnk_goto = 'sql.php'
  1170.                           . '?' . str_replace('&', '&', $url_query)
  1171.                           . '&sql_query=' . urlencode($url_sql_query)
  1172.                           . '&goto=main.php';
  1173.                 $del_url  = 'sql.php?'
  1174.                           . PMA_generate_common_url('mysql')
  1175.                           . '&sql_query=' . urlencode('KILL ' . $row[0])
  1176.                           . '&goto=' . urlencode($lnk_goto);
  1177.                 $del_query = urlencode('KILL ' . $row[0]);
  1178.                 $js_conf  = 'KILL ' . $row[0];
  1179.                 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
  1180.                     $del_str = $GLOBALS['strKill'];
  1181.                 } else {
  1182.                     $del_str = $iconic_spacer . '<img width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" border="0" />';
  1183.                     if ($propicon == 'both') {
  1184.                         $del_str .= ' ' . $GLOBALS['strKill'] . '</div>';
  1185.                     }
  1186.                 }
  1187.             } // end if (1.2.2)
  1188.  
  1189.             // 1.3 Displays the links at left if required
  1190.             if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
  1191.                 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
  1192.                 $doWriteModifyAt = 'left';
  1193.                 require('./libraries/display_tbl_links.lib.php');
  1194.             } // end if (1.3)
  1195.             echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
  1196.         } // end if (1)
  1197.  
  1198.         // 2. Displays the rows' values
  1199.         for ($i = 0; $i < $fields_cnt; ++$i) {
  1200.             $meta    = $fields_meta[$i];
  1201.             // loic1: To fix bug #474943 under php4, the row pointer will
  1202.             //        depend on whether the "is_null" php4 function is
  1203.             //        available or not
  1204.             $pointer = (function_exists('is_null') ? $i : $meta->name);
  1205.             // garvin: See if this column should get highlight because it's used in the
  1206.             //  where-query.
  1207.             if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
  1208.                 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
  1209.             } else {
  1210.                 $column_style = '';
  1211.             }
  1212.  
  1213.             if ($disp_direction == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
  1214.                 if ($GLOBALS['cfg']['BrowsePointerColor'] == TRUE) {
  1215.                     $column_style .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
  1216.                               . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
  1217.                 }
  1218.                 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) {
  1219.                     $column_style .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');"';
  1220.                 } else {
  1221.                     $column_style .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
  1222.                 }
  1223.             } else {
  1224.                 $column_style .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
  1225.             }// end if
  1226.  
  1227.             // garvin: Wrap MIME-transformations. [MIME]
  1228.             $default_function = 'default_function'; // default_function
  1229.             $transform_function = $default_function;
  1230.             $transform_options = array();
  1231.  
  1232.             if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
  1233.  
  1234.                 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
  1235.                     $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
  1236.  
  1237.                     if (file_exists('./libraries/transformations/' . $include_file)) {
  1238.                         $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
  1239.  
  1240.                         require_once('./libraries/transformations/' . $include_file);
  1241.  
  1242.                         if (function_exists('PMA_transformation_' . $transformfunction_name)) {
  1243.                             $transform_function = 'PMA_transformation_' . $transformfunction_name;
  1244.                             $transform_options  = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
  1245.                             $meta->mimetype     = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
  1246.                         }
  1247.                     } // end if file_exists
  1248.                 } // end if transformation is set
  1249.             } // end if mime/transformation works.
  1250.  
  1251.             $transform_options['wrapper_link'] = '?'
  1252.                                                 . (isset($url_query) ? $url_query : '')
  1253.                                                 . '&primary_key=' . (isset($uva_condition) ? $uva_condition : '')
  1254.                                                 . '&sql_query=' . (isset($sql_query) ? urlencode($url_sql_query) : '')
  1255.                                                 . '&goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
  1256.                                                 . '&transform_key=' . urlencode($meta->name);
  1257.  
  1258.  
  1259.             // n u m e r i c
  1260.             if ($meta->numeric == 1) {
  1261.  
  1262.  
  1263.             // lem9: if two fields have the same name (this is possible
  1264.             //       with self-join queries, for example), using $meta->name
  1265.             //       will show both fields NULL even if only one is NULL,
  1266.             //       so use the $pointer
  1267.             //      (works only if function_exists('is_null')
  1268.             // PS:   why not always work with the number ($i), since
  1269.             //       the default second parameter of
  1270.             //       mysql_fetch_array() is MYSQL_BOTH, so we always get
  1271.             //       associative and numeric indices?
  1272.  
  1273.                 //if (!isset($row[$meta->name])
  1274.                 if (!isset($row[$i]) || is_null($row[$i])) {
  1275.                     $vertical_display['data'][$row_no][$i]     = '    <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
  1276.                 } else if ($row[$i] != '') {
  1277.                     $vertical_display['data'][$row_no][$i]     = '    <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '" class="nowrap">';
  1278.  
  1279.                     if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
  1280.                         foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
  1281.                             $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
  1282.                             if (!empty($alias)) {
  1283.                                 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
  1284.                                 if ($alias == $meta->name) {
  1285.                                     $meta->name = $true_column;
  1286.                                 } // end if
  1287.                             } // end if
  1288.                         } // end while
  1289.                     }
  1290.  
  1291.                     if (isset($map[$meta->name])) {
  1292.                         // Field to display from the foreign table?
  1293.                         if (!empty($map[$meta->name][2])) {
  1294.                             $dispsql     = 'SELECT ' . PMA_backquote($map[$meta->name][2])
  1295.                                          . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
  1296.                                          . ' WHERE ' . PMA_backquote($map[$meta->name][1])
  1297.                                          . ' = ' . $row[$i];
  1298.                             $dispresult  = PMA_DBI_try_query($dispsql, NULL, PMA_DBI_QUERY_STORE);
  1299.                             if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
  1300.                                 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
  1301.                             }
  1302.                             else {
  1303.                                 $dispval = $GLOBALS['strLinkNotFound'];
  1304.                             }
  1305.                             @PMA_DBI_free_result($dispresult);
  1306.                         }
  1307.                         else {
  1308.                             $dispval     = '';
  1309.                         } // end if... else...
  1310.  
  1311.                         if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  1312.                             $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ' <code>[->' . $dispval . ']</code>';
  1313.                         } else {
  1314.                             $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
  1315.  
  1316.                             $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
  1317.                                                                    .  PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
  1318.                                                                    .  '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars
  1319.                                                                    .  '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]) . '"' . $title . '>'
  1320.                                                                    .  ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . '</a>';
  1321.                         }
  1322.                     } else {
  1323.                         $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta));
  1324.                     }
  1325.                     $vertical_display['data'][$row_no][$i]     .= '</td>' . "\n";
  1326.                 } else {
  1327.                     $vertical_display['data'][$row_no][$i]     = '    <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '" class="nowrap"> </td>' . "\n";
  1328.                 }
  1329.  
  1330.             //  b l o b
  1331.  
  1332.             } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) {
  1333.                 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
  1334.                 // TEXT fields type, however TEXT fields must be displayed
  1335.                 // even if $cfg['ShowBlob'] is false -> get the true type
  1336.                 // of the fields.
  1337.                 $field_flags = PMA_DBI_field_flags($dt_result, $i);
  1338.                 if (stristr($field_flags, 'BINARY')) {
  1339.                     $blobtext = '[BLOB';
  1340.                     if (!isset($row[$i]) || is_null($row[$i])) {
  1341.                         $blobtext .= ' - NULL';
  1342.                     } elseif (isset($row[$i])) {
  1343.                         $blob_size = PMA_formatByteDown(strlen($row[$i]), 3, 1);
  1344.                         $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
  1345.                         unset($blob_size);
  1346.                     }
  1347.  
  1348.                     $blobtext .= ']';
  1349.                     $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
  1350.  
  1351.                     $vertical_display['data'][$row_no][$i]      = '    <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
  1352.                 } else {
  1353.                     if (!isset($row[$i]) || is_null($row[$i])) {
  1354.                         $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
  1355.                     } else if ($row[$i] != '') {
  1356.                         // garvin: if a transform function for blob is set, none of these replacements will be made
  1357.                         if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
  1358.                             $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
  1359.                         }
  1360.                         // loic1: displays all space characters, 4 space
  1361.                         // characters for tabulations and <cr>/<lf>
  1362.                         $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
  1363.  
  1364.                         $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$i] . '</td>' . "\n";
  1365.                     } else {
  1366.                         $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"> </td>' . "\n";
  1367.                     }
  1368.                 }
  1369.             } else {
  1370.                 if (!isset($row[$i]) || is_null($row[$i])) {
  1371.                     $vertical_display['data'][$row_no][$i]     = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
  1372.                 } else if ($row[$i] != '') {
  1373.                     // loic1: support blanks in the key
  1374.                     $relation_id = $row[$i];
  1375.  
  1376.                     // nijel: Cut all fields to $cfg['LimitChars']
  1377.                     if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
  1378.                         $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
  1379.                     }
  1380.  
  1381.                     // loic1: displays special characters from binaries
  1382.                     $field_flags = PMA_DBI_field_flags($dt_result, $i);
  1383.                     if (stristr($field_flags, 'BINARY')) {
  1384.                         $row[$i]     = str_replace("\x00", '\0', $row[$i]);
  1385.                         $row[$i]     = str_replace("\x08", '\b', $row[$i]);
  1386.                         $row[$i]     = str_replace("\x0a", '\n', $row[$i]);
  1387.                         $row[$i]     = str_replace("\x0d", '\r', $row[$i]);
  1388.                         $row[$i]     = str_replace("\x1a", '\Z', $row[$i]);
  1389.                         $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
  1390.                     }
  1391.                     // loic1: displays all space characters, 4 space
  1392.                     // characters for tabulations and <cr>/<lf>
  1393.                     else {
  1394.                         $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
  1395.                     }
  1396.  
  1397.                     // garvin: transform functions may enable nowrapping:
  1398.                     $function_nowrap = $transform_function . '_nowrap';
  1399.                     $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
  1400.  
  1401.                     // loic1: do not wrap if date field type
  1402.                     $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap="nowrap"' : '');
  1403.                     $vertical_display['data'][$row_no][$i]     = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
  1404.  
  1405.                     if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
  1406.                         foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
  1407.                             $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
  1408.                             if (!empty($alias)) {
  1409.                                 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
  1410.                                 if ($alias == $meta->name) {
  1411.                                     $meta->name = $true_column;
  1412.                                 } // end if
  1413.                             } // end if
  1414.                         } // end while
  1415.                     }
  1416.  
  1417.                     if (isset($map[$meta->name])) {
  1418.                         // Field to display from the foreign table?
  1419.                         if (!empty($map[$meta->name][2])) {
  1420.                             $dispsql     = 'SELECT ' . PMA_backquote($map[$meta->name][2])
  1421.                                          . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
  1422.                                          . ' WHERE ' . PMA_backquote($map[$meta->name][1])
  1423.                                          . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
  1424.                             $dispresult  = PMA_DBI_try_query($dispsql, NULL, PMA_DBI_QUERY_STORE);
  1425.                             if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
  1426.                                 list($dispval) = PMA_DBI_fetch_row($dispresult);
  1427.                                 @PMA_DBI_free_result($dispresult);
  1428.                             }
  1429.                             else {
  1430.                                 $dispval = $GLOBALS['strLinkNotFound'];
  1431.                             }
  1432.                         }
  1433.                         else {
  1434.                             $dispval = '';
  1435.                         }
  1436.                         $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
  1437.  
  1438.                         $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
  1439.                                                                .  PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
  1440.                                                                .  '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars
  1441.                                                                .  '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
  1442.                                                                .  $row[$i] . '</a>';
  1443.                     } else {
  1444.                         $vertical_display['data'][$row_no][$i] .= $row[$i];
  1445.                     }
  1446.                     $vertical_display['data'][$row_no][$i]     .= '</td>' . "\n";
  1447.                 } else {
  1448.                     $vertical_display['data'][$row_no][$i]     = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"> </td>' . "\n";
  1449.                 }
  1450.             }
  1451.  
  1452.             // lem9: output stored cell
  1453.             if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  1454.                 echo $vertical_display['data'][$row_no][$i];
  1455.             }
  1456.  
  1457.             if (isset($vertical_display['rowdata'][$i][$row_no])) {
  1458.                 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
  1459.             } else {
  1460.                 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
  1461.             }
  1462.         } // end for (2)
  1463.  
  1464.         // 3. Displays the modify/delete links on the right if required
  1465.         if ($GLOBALS['cfg']['ModifyDeleteAtRight']
  1466.             && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
  1467.                 $doWriteModifyAt = 'right';
  1468.                 require('./libraries/display_tbl_links.lib.php');
  1469.         } // end if (3)
  1470.  
  1471.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  1472.             echo "\n";
  1473.             ?>
  1474. </tr>
  1475.             <?php
  1476.         } // end if
  1477.  
  1478.         // 4. Gather links of del_urls and edit_urls in an array for later
  1479.         //    output
  1480.         if (!isset($vertical_display['edit'][$row_no])) {
  1481.             $vertical_display['edit'][$row_no]       = '';
  1482.             $vertical_display['delete'][$row_no]     = '';
  1483.             $vertical_display['row_delete'][$row_no] = '';
  1484.         }
  1485.  
  1486.         $column_style_vertical = '';
  1487.         if ($GLOBALS['cfg']['BrowsePointerEnable'] == TRUE) {
  1488.             $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
  1489.                          . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
  1490.         }
  1491.         $column_marker_vertical = '';
  1492.         if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) {
  1493.             $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');';
  1494.         }
  1495.  
  1496.         if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
  1497.             $vertical_display['row_delete'][$row_no] .= '    <td align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '"' . $column_style_vertical . '>' . "\n"
  1498.                                                      .  '        <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $uva_condition . ']"'
  1499.                                                      .  ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
  1500.                                                      .  ' value="' . $del_query . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
  1501.                                                      .  '    </td>' . "\n";
  1502.         } else {
  1503.             unset($vertical_display['row_delete'][$row_no]);
  1504.         }
  1505.  
  1506.         if (isset($edit_url)) {
  1507.             $vertical_display['edit'][$row_no]   .= '    <td align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '"' . $column_style_vertical . '>' . "\n"
  1508.                                                  . PMA_linkOrButton($edit_url, $edit_str, '', FALSE)
  1509.                                                  . $bookmark_go
  1510.                                                  .  '    </td>' . "\n";
  1511.         } else {
  1512.             unset($vertical_display['edit'][$row_no]);
  1513.         }
  1514.  
  1515.         if (isset($del_url)) {
  1516.             $vertical_display['delete'][$row_no] .= '    <td align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '"' . $column_style_vertical . '>' . "\n"
  1517.                                                  . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), FALSE)
  1518.                                                  .  '    </td>' . "\n";
  1519.         } else {
  1520.             unset($vertical_display['delete'][$row_no]);
  1521.         }
  1522.  
  1523.         echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
  1524.         $row_no++;
  1525.     } // end while
  1526.  
  1527.     if (isset($url_query)) {
  1528.         $GLOBALS['url_query'] = $url_query;
  1529.     }
  1530.  
  1531.     return TRUE;
  1532. } // end of the 'PMA_displayTableBody()' function
  1533.  
  1534.  
  1535. /**
  1536.  * Do display the result table with the vertical direction mode.
  1537.  * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
  1538.  *
  1539.  * @return  boolean  always true
  1540.  *
  1541.  * @global  array    the information to display
  1542.  * @global  integer  the number of row to display between two table headers
  1543.  *
  1544.  * @access  private
  1545.  *
  1546.  * @see     PMA_displayTable()
  1547.  */
  1548. function PMA_displayVerticalTable()
  1549. {
  1550.     global $vertical_display, $repeat_cells;
  1551.  
  1552.     // Displays "multi row delete" link at top if required
  1553.     if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
  1554.         echo '<tr>' . "\n";
  1555.         echo $vertical_display['textbtn'];
  1556.         $foo_counter = 0;
  1557.         foreach ($vertical_display['row_delete'] AS $key => $val) {
  1558.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1559.                 echo '<th class="td"> </th>' . "\n";
  1560.             }
  1561.  
  1562.             echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
  1563.             $foo_counter++;
  1564.         } // end while
  1565.         echo '</tr>' . "\n";
  1566.     } // end if
  1567.  
  1568.     // Displays "edit" link at top if required
  1569.     if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
  1570.         echo '<tr>' . "\n";
  1571.         if (!is_array($vertical_display['row_delete'])) {
  1572.             echo $vertical_display['textbtn'];
  1573.         }
  1574.         $foo_counter = 0;
  1575.         foreach ($vertical_display['edit'] AS $key => $val) {
  1576.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1577.                 echo '    <th class="td"> </th>' . "\n";
  1578.             }
  1579.  
  1580.             echo $val;
  1581.             $foo_counter++;
  1582.         } // end while
  1583.         echo '</tr>' . "\n";
  1584.     } // end if
  1585.  
  1586.     // Displays "delete" link at top if required
  1587.     if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
  1588.         echo '<tr>' . "\n";
  1589.         if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
  1590.             echo $vertical_display['textbtn'];
  1591.         }
  1592.         $foo_counter = 0;
  1593.         foreach ($vertical_display['delete'] AS $key => $val) {
  1594.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1595.                 echo '<th class="td"> </th>' . "\n";
  1596.             }
  1597.  
  1598.             echo $val;
  1599.             $foo_counter++;
  1600.         } // end while
  1601.         echo '</tr>' . "\n";
  1602.     } // end if
  1603.  
  1604.     // Displays data
  1605.     $row_no = 0;
  1606.     foreach ($vertical_display['desc'] AS $key => $val) {
  1607.         $row_no++;
  1608.  
  1609.         if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
  1610.             $bgcolor = '#ffffff';
  1611.         } else {
  1612.             $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
  1613.         }
  1614.  
  1615.         echo '<tr>' . "\n";
  1616.         echo $val;
  1617.  
  1618.         $foo_counter = 0;
  1619.         foreach ($vertical_display['rowdata'][$key] AS $subkey => $subval) {
  1620.             if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
  1621.                 echo $val;
  1622.             }
  1623.  
  1624.             echo $subval;
  1625.             $foo_counter++;
  1626.         } // end while
  1627.  
  1628.         echo '</tr>' . "\n";
  1629.     } // end while
  1630.  
  1631.     // Displays "multi row delete" link at bottom if required
  1632.     if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
  1633.         echo '<tr>' . "\n";
  1634.         echo $vertical_display['textbtn'];
  1635.         $foo_counter = 0;
  1636.         foreach ($vertical_display['row_delete'] AS $key => $val) {
  1637.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1638.                 echo '<th class="td"> </th>' . "\n";
  1639.             }
  1640.  
  1641.             echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
  1642.             $foo_counter++;
  1643.         } // end while
  1644.         echo '</tr>' . "\n";
  1645.     } // end if
  1646.  
  1647.     // Displays "edit" link at bottom if required
  1648.     if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
  1649.         echo '<tr>' . "\n";
  1650.         if (!is_array($vertical_display['row_delete'])) {
  1651.             echo $vertical_display['textbtn'];
  1652.         }
  1653.         $foo_counter = 0;
  1654.         foreach ($vertical_display['edit'] AS $key => $val) {
  1655.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1656.                 echo '<th class="td"> </th>' . "\n";
  1657.             }
  1658.  
  1659.             echo $val;
  1660.             $foo_counter++;
  1661.         } // end while
  1662.         echo '</tr>' . "\n";
  1663.     } // end if
  1664.  
  1665.     // Displays "delete" link at bottom if required
  1666.     if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
  1667.         echo '<tr>' . "\n";
  1668.         if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
  1669.             echo $vertical_display['textbtn'];
  1670.         }
  1671.         $foo_counter = 0;
  1672.         foreach ($vertical_display['delete'] AS $key => $val) {
  1673.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1674.                 echo '<th class="td"> </th>' . "\n";
  1675.             }
  1676.  
  1677.             echo $val;
  1678.             $foo_counter++;
  1679.         } // end while
  1680.         echo '</tr>' . "\n";
  1681.     }
  1682.  
  1683.     return TRUE;
  1684. } // end of the 'PMA_displayVerticalTable' function
  1685.  
  1686.  
  1687. /**
  1688.  * Displays a table of results returned by a sql query.
  1689.  * This function is called by the "sql.php" script.
  1690.  *
  1691.  * @param   integer the link id associated to the query which results have
  1692.  *                  to be displayed
  1693.  * @param   array   the display mode
  1694.  * @param   array   the analyzed query
  1695.  *
  1696.  * @global  string   the current language
  1697.  * @global  integer  the server to use (refers to the number in the
  1698.  *                   configuration file)
  1699.  * @global  array    the current server config
  1700.  * @global  string   the database name
  1701.  * @global  string   the table name
  1702.  * @global  string   the url to go back in case of errors
  1703.  * @global  string   the current sql query
  1704.  * @global  integer  the total number of rows returned by the sql query
  1705.  * @global  integer  the total number of rows returned by the sql query
  1706.  *                   without any programmatically appended "LIMIT" clause
  1707.  * @global  integer  the current postion of the first record to be
  1708.  *                   displayed
  1709.  * @global  array    the list of fields properties
  1710.  * @global  integer  the total number of fields returned by the sql query
  1711.  * @global  array    informations used with vertical display mode
  1712.  * @global  string   the display mode (horizontal/vertical/horizontalflipped)
  1713.  * @global  integer  the number of row to display between two table headers
  1714.  * @global  boolean  whether to limit the number of displayed characters of
  1715.  *                   text type fields or not
  1716.  * @global  array    the relation settings
  1717.  *
  1718.  * @access  private
  1719.  *
  1720.  * @see     PMA_showMessage(), PMA_setDisplayMode(),
  1721.  *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
  1722.  *          PMA_displayTableBody()
  1723.  */
  1724. function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
  1725. {
  1726.     global $lang, $server, $cfg, $db, $table;
  1727.     global $goto, $text_url;
  1728.     global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
  1729.     global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
  1730.     global $dontlimitchars;
  1731.     global $cfgRelation;
  1732.  
  1733.     // 1. ----- Prepares the work -----
  1734.  
  1735.     // 1.1 Gets the informations about which functionnalities should be
  1736.     //     displayed
  1737.     $total      = '';
  1738.     $is_display = PMA_setDisplayMode($the_disp_mode, $total);
  1739.     if ($total == '') {
  1740.         unset($total);
  1741.     }
  1742.  
  1743.     // 1.2 Defines offsets for the next and previous pages
  1744.     if ($is_display['nav_bar'] == '1') {
  1745.         if (!isset($pos)) {
  1746.             $pos          = 0;
  1747.         }
  1748.         if ($GLOBALS['session_max_rows'] == 'all') {
  1749.             $pos_next     = 0;
  1750.             $pos_prev     = 0;
  1751.         } else {
  1752.             $pos_next     = $pos + $GLOBALS['cfg']['MaxRows'];
  1753.             $pos_prev     = $pos - $GLOBALS['cfg']['MaxRows'];
  1754.             if ($pos_prev < 0) {
  1755.                 $pos_prev = 0;
  1756.             }
  1757.         }
  1758.     } // end if
  1759.  
  1760.     // 1.3 Urlencodes the query to use in input form fields
  1761.     $encoded_sql_query = urlencode($sql_query);
  1762.  
  1763.     // 2. ----- Displays the top of the page -----
  1764.  
  1765.     // 2.1 Displays a messages with position informations
  1766.     if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
  1767.         if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
  1768.             $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
  1769.         } else {
  1770.             $selectstring = '';
  1771.         }
  1772.         $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
  1773.                         ? $total - 1
  1774.                         : $pos_next - 1;
  1775.         PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
  1776.     } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  1777.         PMA_showMessage($GLOBALS['strSQLQuery']);
  1778.     }
  1779.  
  1780.     // 2.3 Displays the navigation bars
  1781.     if (!isset($table) || strlen(trim($table)) == 0) {
  1782.         $table = $fields_meta[0]->table;
  1783.     }
  1784.     if ($is_display['nav_bar'] == '1') {
  1785.         PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
  1786.         echo "\n";
  1787.     } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  1788.         echo "\n" . '<br /><br />' . "\n";
  1789.     }
  1790.  
  1791.     // 2b ----- Get field references from Database -----
  1792.     // (see the 'relation' config variable)
  1793.     // loic1, 2002-03-02: extended to php3
  1794.  
  1795.     // init map
  1796.     $map = array();
  1797.  
  1798.     // find tables
  1799.  
  1800.     $target=array();
  1801.     if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
  1802.         foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
  1803.            $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
  1804.         }
  1805.     }
  1806.     $tabs    = '(\'' . join('\',\'', $target) . '\')';
  1807.  
  1808.     if ($cfgRelation['displaywork']) {
  1809.         if (empty($table)) {
  1810.             $exist_rel = FALSE;
  1811.         } else {
  1812.             $exist_rel = PMA_getForeigners($db, $table, '', 'both');
  1813.             if ($exist_rel) {
  1814.                 foreach ($exist_rel AS $master_field => $rel) {
  1815.                     $display_field = PMA_getDisplayField($rel['foreign_db'],$rel['foreign_table']);
  1816.                     $map[$master_field] = array($rel['foreign_table'],
  1817.                                           $rel['foreign_field'],
  1818.                                           $display_field,
  1819.                                           $rel['foreign_db']);
  1820.                 } // end while
  1821.             } // end if
  1822.         } // end if
  1823.     } // end if
  1824.     // end 2b
  1825.  
  1826.     // 3. ----- Displays the results table -----
  1827.     PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
  1828.     $url_query='';
  1829.     PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
  1830.     // vertical output case
  1831.     if ($disp_direction == 'vertical') {
  1832.         PMA_displayVerticalTable();
  1833.     } // end if
  1834.     unset($vertical_display);
  1835.     ?>
  1836. </table>
  1837.     <?php
  1838.  
  1839.     echo "\n";
  1840.  
  1841.     // 4. ----- Displays the link for multi-fields delete
  1842.  
  1843.     if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
  1844.  
  1845.         $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
  1846.         $propicon = (string)$GLOBALS['cfg']['PropertiesIconic'];
  1847. ?>
  1848.           <img src="<?php echo $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png'; ?>" border="0" width="38" height="22" alt="<?php echo $GLOBALS['strWithChecked']; ?>" />
  1849.         <a href="<?php echo $text_url . '&checkall=1'; ?>" onclick="setCheckboxesRange('rowsDeleteForm', true, 'id_rows_to_delete', 0, '<?php echo $num_rows; ?>'); return false;">
  1850.             <?php echo $GLOBALS['strCheckAll']; ?></a>
  1851.          / 
  1852.         <a href="<?php echo $text_url; ?>" onclick="setCheckboxesRange('rowsDeleteForm', false, 'id_rows_to_delete', 0, '<?php echo $num_rows; ?>'); return false;">
  1853.             <?php echo $GLOBALS['strUncheckAll']; ?></a>
  1854. <?php
  1855.           echo '  <i>' . $GLOBALS['strWithChecked'] . '</i>'. "\n";
  1856.  
  1857.         if ($cfg['PropertiesIconic']) {
  1858.             PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
  1859.             PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_delete', $delete_text, 'b_drop.png');
  1860.             if ($analyzed_sql[0]['querytype'] == 'SELECT') {
  1861.                 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', $GLOBALS['strExport'], 'b_tblexport.png');
  1862.             }
  1863.             echo "\n";
  1864.         } else {
  1865.             echo '                    <input type="submit" name="submit_mult" value="' . htmlspecialchars($GLOBALS['strEdit']) . '" title="' . $GLOBALS['strEdit'] . '" />' . "\n";
  1866.             echo ' <input type="submit" name="submit_mult" value="' . htmlspecialchars($delete_text) . '" title="' . $delete_text . '" />' . "\n";
  1867.             if ($analyzed_sql[0]['querytype'] == 'SELECT') {
  1868.                 echo ' <input type="submit" name="submit_mult" value="' . htmlspecialchars($GLOBALS['strExport']) . '" title="' . $GLOBALS['strExport'] . '" />' . "\n";
  1869.             }
  1870.         }
  1871.         echo '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />' . "\n";
  1872.         echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
  1873.         echo '<input type="hidden" name="url_query" value="' . $GLOBALS['url_query'] . '" />' . "\n";
  1874.         echo '<br />' . "\n";
  1875.         echo '</form>' . "\n";
  1876.     }
  1877.  
  1878.     // 5. ----- Displays the navigation bar at the bottom if required -----
  1879.  
  1880.     if ($is_display['nav_bar'] == '1') {
  1881.         echo '<br />' . "\n";
  1882.         PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
  1883.     } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  1884.         echo "\n" . '<br /><br />' . "\n";
  1885.     }
  1886. } // end of the 'PMA_displayTable()' function
  1887.  
  1888. function default_function($buffer) {
  1889.     $buffer = htmlspecialchars($buffer);
  1890.     $buffer = str_replace("\011", '    ', str_replace('  ', '  ', $buffer));
  1891.     $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
  1892.  
  1893.     return $buffer;
  1894. }
  1895. ?>
  1896.